package cn.oinch.bangbang.config.condition.utils;

import cn.oinch.bangbang.common.constants.Env;
import lombok.NoArgsConstructor;
import lombok.extern.log4j.Log4j2;

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

/**
 * 读取环境变量
 *
 * @author sunHaoMing
 */
@Log4j2
@NoArgsConstructor
public class PropertiesUtil {
    public static String getProperties(String propertiesName, String defaultValue) {
        try (FileInputStream inputStream = new FileInputStream(new File(Env.ENV_FILE_PATH))) {
            Properties properties = new Properties();
            properties.load(inputStream);
            return properties.getProperty(propertiesName, defaultValue);
        } catch (Exception e) {
            log.error("not found env properties file:", e.getMessage());
        }
        return defaultValue;
    }
}
